$(function() {
	var jianliid = $("#jianli");
	// 初始化
	var zhi = null;
	jianliid.datagrid({
		url : 'jianli/jianli',
		fit : true,
		rownumbers : true,
		pagination : true, // 是否显示分页栏
		columns : [ [
				{
					field : 'user_name',
					title : '姓名',
					align : 'center',
					width : 100
				},
				{
					field : 'gender',
					title : '性别',
					align : 'center',
					width : 50,
					formatter : function(value, row, index) {
						if (value == "1") {
							value = '<img style="width:35px; height:35px" src="public/images/girl.png">';
							return value;
						}
							value = '<img style="width:40px; height:40px" src="public/images/boy.png">';
							return value;
					}
				},
				{
					field : 'contact_num',
					title : '电话',
					align : 'center',
					width : 100
				},
				{
					field : 'state',
					title : '就业情况',
					align : 'center',
					width : 100,
					formatter : function(value, row, index) {
						zhi = value;
						if (value == "3") {
							return "就业中";
						}
						return "已就业";
					}
				},
				{
					field : 'ac',
					title : '操作',
					width : 150,
					align : 'center',
					formatter : function(value, row, index) {
						var bts = [];
						if (zhi == "4") {
							bts.push('<a data-index="' + index
									+ '" class="ctr genjin">跟进</a>');
						}

						bts.push('<a data-index="' + index
								+ '" class="ctr pingjia">进行批阅评价</a>');
						return bts.join('');
					}
				} ] ]
	});
	/**
	 * 查看简历
	 */
	var gridpanel = jianliid.datagrid("getPanel");
	gridpanel.on("click", "a.pingjia", function() {
		var index = this.dataset.index;
		var rows = jianliid.datagrid("getRows");
		var id = rows[index].studentinfo_id;
		mianshiForm(id);
	}).on("click", "a.genjin", function() {
		var index = this.dataset.index;
		var rows = jianliid.datagrid("getRows");
		var id = rows[index].studentinfo_id;
		genjincaozuo(id);
	});
	/**
	 * 重置
	 */
	var form = $("#jianliSearchForm");
	$("#jianliReset").on('click', function() {
		form.form('clear');
		// 清除查询参数
		jianliid.datagrid("load", {});
	});

	var resumeGraduation = $("#jianliTel");
	$("#jianliSearch").on('click', function() {
		jianliid.datagrid("load", {
			resumeGraduation : "%" + resumeGraduation.val() + "%",
		});
	});

	function mianshiForm(id) {
		var dialog = $("<div/>").dialog(
				{
					href : 'jianli/jy-jl-tianjiajianli'
							+ (id ? ("/" + id) : ""),
					title : '添加面试经验试题',
					height : '600',
					width : '700',
					modal : true,
					onClose : function() {
						// 窗口关闭的同时销毁此窗口
						$(this).dialog("destroy");
					},
					buttons : [ {
						iconCls : 'icon-save',
						text : '保存',
						handler : function() {
							var pingjiaForm = $("#pingjiaForm");
							if (pingjiaForm.form('validate')) {
								$.post("jianli/save", pingjiaForm.serialize(),
										function(rs) {
											if (rs.success) {
												// 刷新数据表格
												jianliid.datagrid("reload");
												// 关闭窗口
												dialog.dialog("close");
											} else {
												$.messager.alert("提示",
														rs.message);
											}
										});
							}

						}
					} ]

				});
	}

	function genjincaozuo(id) {
		var dialog = $("<div/>").dialog({
			href : 'zs-followuprecord/zs-genjinfollowuprecord' + (id ? ("/" + id) : ""),
			title : '进行跟进',
			height: 380,
			width: 450,
			modal : true,
			onClose : function() {
				// 窗口关闭的同时销毁此窗口
				$(this).dialog("destroy");
			},
			buttons : [ {
				iconCls : 'icon-save',
				text : '保存',
				handler: function() {
					var followForm = $("#followForm");
					if(followForm.form('validate')) {
						$.post("zs-followuprecord/save", followForm.serialize(), function(rs) {
							jianliid.datagrid("reload");
							dialog.dialog("close");
						});
					}
				}
			} ]

		});
	}

});